﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CMS.BLL;

public partial class Controls_ContactUs_ctrContactUs : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //rfvEmail.ErrorMessage = MessagesAlert.EMAIL_SEND_FAIL;  
            SetLabel();

        }
    }

    private void SetLabel()
    {
        int nCurrentLanguage = Support.GetCurrentLanguage();
    //    lblBranchOffice.Text = MultipleLanguage.BRACH2[nCurrentLanguage - 1];
        lblContact.Text = MultipleLanguage.CONTACT[nCurrentLanguage - 1].ToUpper();
        lblEmail.Text = MultipleLanguage.EMAIL[nCurrentLanguage - 1];
        lblFullName.Text = MultipleLanguage.FULLNAME[nCurrentLanguage - 1];
      //  lblHeadOffice.Text = MultipleLanguage.BRACH1[nCurrentLanguage - 1];
        lblInputRequire.Text = MultipleLanguage.INPUTREQUIRE[nCurrentLanguage - 1]; 
        lblMainContent.Text  = MultipleLanguage.CONTENT [nCurrentLanguage - 1];
        lblTelephone.Text = MultipleLanguage.TELEPHONE[nCurrentLanguage - 1];
        btnSend.Text = MultipleLanguage.SEND[nCurrentLanguage - 1];   
        Company objCompany = new Company();
        DataTable dtbCompany = new DataTable();
        dtbCompany = objCompany.Search();
        int nCompanyCount = dtbCompany.Rows.Count;
        int nCompanyLastestID = ConvertData.ConvertToInt(dtbCompany.Rows[nCompanyCount - 1]["CompanyID"]);
        objCompany.LoadById(nCompanyLastestID);

        switch (nCurrentLanguage )
        {
            case 1:
                lblBranchOfficeAdd.Text = objCompany.Data.BranchAddress1 ;
                lblCompanyName.Text = objCompany.Data.CompanyName1.ToUpper();
                lblHeadOfficeAdd.Text = objCompany.Data.Address1;
                lblBranchCompanyName.Text = objCompany.Data.BranchCompanyName1.ToUpper();
                break;
            case 2:
                lblBranchOfficeAdd.Text = objCompany.Data.BranchAddress2;
                lblCompanyName.Text = objCompany.Data.CompanyName2.ToUpper();
                lblHeadOfficeAdd.Text = objCompany.Data.Address2;
                lblBranchCompanyName.Text = objCompany.Data.BranchCompanyName2.ToUpper();
              
                break;
            case 3:
                lblBranchOfficeAdd.Text = objCompany.Data.BranchAddress3;
                lblCompanyName.Text = objCompany.Data.CompanyName3.ToUpper();
                lblHeadOfficeAdd.Text = objCompany.Data.Address3;
                lblBranchCompanyName.Text = objCompany.Data.BranchCompanyName3.ToUpper();
                break;
        }
        lblBranchOfficeEmail.Text = objCompany.Data.BranchEmail ;
        lblBranchOfficeFax.Text = objCompany.Data.BranchFax;
        lblBranchOfficeHotline.Text = objCompany.Data.BranchHotline;
        lblBranchOfficeTel.Text = objCompany.Data.BranchTel;
        lblHeadOfficeEmail.Text = objCompany.Data.Email;
        lblHeadOfficeFax.Text = objCompany.Data.Fax;
        lblHeadOfficeHotline.Text = objCompany.Data.Hotline;
        lblHeadOfficeTel.Text = objCompany.Data.Tel;
         
    
    }
  
    private void ClearForm()
    {
        txtEmail.Text = string.Empty;
        txtFullName.Text = string.Empty;
        txtMainContent.Text = string.Empty;
        txtTelephone.Text = string.Empty;
    }
    protected void btnSend_Click1(object sender, EventArgs e)
    {
        Contacts objContact = new Contacts();
        objContact.Data.Email = ConvertData.ConvertToString(txtEmail.Text.Trim());
        objContact.Data.Telephone = ConvertData.ConvertToString(txtTelephone.Text.Trim());
        objContact.Data.Fullname = ConvertData.ConvertToString(txtFullName.Text.Trim());
        objContact.Data.MainContent = ConvertData.ConvertToString(txtMainContent.Text.Trim());
        objContact.Data.Status = 0;
        objContact.Data.CreatedDate = ConvertData.ConvertDatetimeToInt(DateTime.Today);

        int nResult = objContact.Insert();
        int iCurrentLang = Support.GetCurrentLanguage();
        if (nResult > 0)
        {

            Alert1.ShowMessage(1, MultipleLanguage.CONTACT_SENT[iCurrentLang -1]);
            ClearForm();
        }
        else { Alert1.ShowMessage(2, MultipleLanguage.CONTACT_SEND_FAIL[iCurrentLang - 1]); }
    }
}
